package com.shockweb.common.context;

import org.aspectj.lang.JoinPoint;


/**
 * 微服务 aop 切面： 业务切面
 *
 * @author 彭明华 2017.06.30
 */
public class ContextAop {
	
	/**
	 * 处理上下文
	 * @param joinPoint
	 */
    public void doBefore(JoinPoint joinPoint) {
    	for(Object param:joinPoint.getArgs()){
    		if(param instanceof ContextParam){
    			ContextParam cp = (ContextParam)param;
    			ContextManager.putAll(cp);
    			break;
    		}
    		if(param instanceof ServiceParam){
    			ServiceParam<?> sp = (ServiceParam<?>)param;
    			ContextManager.putAll(sp.getContextParam());
    			break;
    		}
    	}
    }
    
	/**
	 * 处理上下文
	 * @param joinPoint
	 */
    public void doAfter(JoinPoint joinPoint) {
    	ContextManager.remove();
    }
    

}